﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using 海漫思考核.BLL;
using 海漫思考核.DAL;

namespace 海漫思考核
{
    public partial class NoveList : System.Web.UI.Page
    {
        private static int index = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)//第一次加载
            {
                if (Session["User"] != null)
                {
                    var types = NoveBLL.SelectAllNoveType();//获取所有的小说类型
                foreach (NoveType item in types)//给前端小说类型下拉框赋值
                {
                    ddl_type.Items.Add(item.Tname);
                    ddl_type.Items[item.Tid].Value = item.Tname;
                }
                ShowData();//显示数据
                }
                else
                {
                    Response.Write("<script>alert('非法登录!即将返回登录页面!');location.href = 'Login.aspx';</script>");
                }
            }
        }
        /// <summary>
        /// 显示数据
        /// </summary>
        public void ShowData()
        {
            if (index == 0)//禁用上一页按键
                btn_up.Enabled = false;
            else
                btn_up.Enabled = true;
            if (NoveBLL.NoveCount() <= (index + 1) * 8)//禁用下一页按键
                btn_down.Enabled = false;
            else
                btn_down.Enabled = true;
            span_index.InnerHtml = "第" + (index + 1) + "页";
            //获取所有小说并绑定到前端页面
            rpt_list.DataSource = NoveBLL.SelectNove(ddl_time.SelectedValue, ddl_type.SelectedValue, text_Novename.Text, index);
            rpt_list.DataBind();
        }
        /// <summary>
        /// 当下拉框或文本框的值发生改变时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnChanged(object sender, EventArgs e)
        {
            ShowData();
        }
        /// <summary>
        /// 上一页点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_up_Click(object sender, EventArgs e)
        {
            index -= 1;
            ShowData();
        }
        /// <summary>
        /// 下一页点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_down_Click(object sender, EventArgs e)
        {
            index += 1;
            ShowData();
        }
    }
}